﻿<?php
       ob_clean();

            //分类数据结构重组
           // $cate = arry();

            $pid = !empty($_GET['id'])?$_GET['id']:0;

            //树状型列表
            $sql = "select * from `cate` where pid=$pid";
            $result = mysqli_query($link,$sql);

              while ($arr = mysqli_fetch_assoc($result)){
                 $cate[] = $arr;
              }

              //判断是否是ajax请求
            if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

                  echo json_encode($cate);

                  die;
            }




            /*递归形式*/
          //      $cate = array();

          //      $cate = getCate();

          // // print_r($cate);die;
          // function getCate($pid=0,$cate=array()){

          //      $sql="SELECT * FROM  `cate` where pid=$pid ";

          //      $data = mysqli_query($GLOBALS['link'],$sql);

          //      while ($arr = mysqli_fetch_assoc($data)){

          //         $cate[]=$arr;

          //         $pid = $arr['id'];

          //         $cate = getCate($pid, $cate);


                  // getCate($pid, $cate){
                  //     $sql="SELECT * FROM  `cate` where pid=$pid ";

                  //      $data = mysqli_query($GLOBALS['link'],$sql);

                  //      while ($arr = mysqli_fetch_assoc($data)){

                  //         $cate[]=$arr;

                  //         $pid = $arr['id'];

                  // $sql="SELECT * FROM  `cate` where pid=$pid ";//查询国际新闻的下一集
                  //  $data = mysqli_query($GLOBALS['link'],$sql)
                  //   while ($arr = mysqli_fetch_assoc($data)){
                  //     $cate[]=$arr;

                  //     $sql="SELECT * FROM  `cate` where pid=$pid ";
                  //      $data = mysqli_query($GLOBALS['link'],$sql)
                  //       while ($arr = mysqli_fetch_assoc($data)){

                  //   }

          //       }
          //     return $cate;

          // }




          // print_r($cate);die;
          /*原生代码*/
             //分类数据结构重组
         //   $cate = array();
         //    //先查找顶级 查询条件 pid=0
         //  $sql="SELECT * FROM  `cate` where pid=0 ";



         //     // 执行数据库语句
         // $data=mysqli_query($link,$sql);


         // while ($arr = mysqli_fetch_assoc($data)){

         //       $cate[]=$arr;

         //       $pid = $arr['id'];

         //       $sql="SELECT * FROM  `cate` where pid=$pid ";


         //       $data1 = mysqli_query($link,$sql);


         //  while ($arr1 = mysqli_fetch_assoc($data1)){

         //        $cate[]=$arr1;

         //        $pid = $arr1['id'];

         //       $sql="SELECT * FROM  `cate` where pid=$pid ";



         //       $data2 = mysqli_query($link,$sql);

         //  while ($arr2 = mysqli_fetch_assoc($data2)){

         //        $cate[]=$arr2;

         //        $pid = $arr2['id'];

         //       $sql="SELECT * FROM  `cate` where pid=$pid ";

         //     }
         //   }

         // }
// print_r($cate);
// echo '<br>';
   include_once (VIEW_PATH.'admin/layout.html');

